package com.lc.controller;

import com.lc.constant.Constants;
import com.lc.pojo.dto.OmsOrderPreSubmitDto;
import com.lc.pojo.param.SkuInfoParam;
import com.lc.result.Result;
import com.lc.result.ResultUtils;
import com.lc.service.OmsOrderService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 订单信息
 * @Author lc
 */

@RestController
@RequestMapping("/oms/order")
public class OmsOrderController {

    @Resource
    private OmsOrderService omsOrderService;

    //订单预支付信息接口
    @PostMapping("/preSubmit")
    public Result preSubmit(@RequestBody SkuInfoParam skuInfos, HttpServletRequest request){
        String token = request.getHeader(Constants.Redis.PREFIX_TOKEN);
        if(!StringUtils.hasLength(token)){
            return ResultUtils.returnFail("查看订单预支付信息前，请登录");
        }

//        List<OmsOrderPreSubmitDto> preSubmit = omsOrderService.getPreSubmit(skuInfos);

        OmsOrderPreSubmitDto preSubmit = omsOrderService.getPreSubmit(skuInfos);
        if(preSubmit != null){
            return ResultUtils.returnDataSuccess(preSubmit);
        }

//        if(!preSubmit.isEmpty()){
//            return ResultUtils.returnDataSuccess(preSubmit);
//        }
        return ResultUtils.returnFail();
    }

}
